﻿using Microsoft.EntityFrameworkCore;
using ServerManager.Data;
using ServerManager.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ServerManager.Repository
{
    public class AppRepository : EfRepository<App>, IAppRepository
    {
        private readonly ApplicationDbContext _dbContext;

        public AppRepository(ApplicationDbContext dbContext)
            : base(dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task<IEnumerable<App>> GetList()
        {
            var apps = await _dbContext.Apps.Include(x => x.Server).ToListAsync();
            return apps;
        }

        public async Task<App> GetById(int id)
        {
            var app = await _dbContext.Apps.Include(x => x.Server).Where(x => x.Id == id).FirstOrDefaultAsync();
            return app;
        }
    }
}
